package com.classicmodels.model;

import java.sql.Connection;
import java.sql.DriverManager;

public class Datasource {

    private static Connection connection;

    public static Connection getConnection() throws Exception {
        if(connection == null) {
            connection = conectarBaseDeDatos();
        }
        return connection;
    }

    private static final String CONNECTION_STRING = "jdbc:mysql://127.0.0.1/classic_models_inc";
    private static final String USUARIO = "root";
    private static final String PASSWORD = "laureano";
    // Se conecta a la base de datos y me devuelve un objeto connection

    private static Connection conectarBaseDeDatos() throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        Connection c = DriverManager.getConnection(CONNECTION_STRING, USUARIO, PASSWORD);
        return c;
    }
}
